package com.zdkj.subway.support.util;

import lombok.experimental.UtilityClass;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Gofe
 * @version 1.0
 * @project subway
 * @package com.zdkj.subway.support.util
 * @createDate 2020/10/10 16:26
 * @modfiyDate
 * @function 时间转换工具
 */
@UtilityClass
public class DateUtilSupport {
    /**
     * LocalDateTime转成String类型的时间00.00.00
     * @param date
     * @return
     */
    public String asDateString(LocalDateTime date) {
        Date time=Date.from(date.atZone(ZoneId.systemDefault()).toInstant());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        // 0时0分0秒
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String localTime = df.format(calendar.getTime());
        return localTime;
    }
    /**
     * LocalDateTime转成String类型的时间23.59.59
     * @param date
     * @return
     */
    public String asDateString2(LocalDateTime date) {
        Date time=Date.from(date.atZone(ZoneId.systemDefault()).toInstant());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        // 23时59分59秒
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String localTime = df.format(calendar.getTime());
        return localTime;
    }
}
